package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "品牌规格")
@RestController
@RequestMapping(value="/admin/product/productSpec")
public class ProductSpecController {

    @Autowired
    ProductSpecService productSpecService;


    @Operation(summary = "查询所有的品牌规格")
    @GetMapping("findAll")
    public Result findAll(){
       List<ProductSpec> list =  productSpecService.findAll();
       return Result.build(list,ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "品牌规格分页查询")
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<ProductSpec>> findByPage(@PathVariable Integer page,@PathVariable Integer limit){
        PageInfo<ProductSpec> pageInfo = productSpecService.findByPage(page,limit);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "品牌规格修改")
    @PutMapping("updateById")
    public Result updateById(@RequestBody ProductSpec productSpec){
        productSpecService.updateById(productSpec);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "品牌规格删除")
    @DeleteMapping("/deleteById/{id}")
    public Result deletedById(@PathVariable Long id){

        productSpecService.deletedById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }
    @Operation(summary = "品牌规格添加")
    @PostMapping("save")
    public Result save(@RequestBody ProductSpec productSpec){

        productSpecService.save(productSpec);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
}
